﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FileIndexer.Model;
using FileIndexer.DAL;

namespace FileIndexer.Repository
{
    class TextRepository
    {         //Generar  nuevo registro de documento
        public void NvoTxt(IdTextModel Text) 
        {

            using (var entity= new FileIndexer.DAL.FileIndexerDB_r1Entities())
            {
                var res = (from o in entity.IDX_TEXT
                           where o.IdDocument == Text.IdDocument
                           select o).FirstOrDefault();


                if (res == null)
                {
                    entity.IDX_TEXT.AddObject(new IDX_TEXT()
                         {
                            //IdDocument=Text.IdDocument,   GENERADO CON UNID
                            Type = Text.Type,
                            Text = Text.Text,
                            FileName = Text.FileName
                         });               
                }

                entity.SaveChanges();        
            }             
         }

        //Generar UNID _id 
        public void NvoText(IdTextModel Text, bool GenerateId)
        {
            if (GenerateId)
            {
                Text.IdDocument= (new UNID()).getNewUNID();
            }

            //this.NvoText(Text); // review 

        }

    }
}
